package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.ExamPaperAnswerMapper;
import com.fc.test.model.auto.ExamPaperAnswer;
import com.fc.test.model.auto.ExamPaperAnswerExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 *  ExamPaperAnswerService
 * @Title: ExamPaperAnswerService.java 
 * @Package com.fc.test.service 
 * @author martins_自动生成
 * @email 610817750@qq.com
 * @date 2019-12-03 12:39:26  
 **/
@Service
public class ExamPaperAnswerService implements BaseService<ExamPaperAnswer, ExamPaperAnswerExample>{
	@Autowired
	private ExamPaperAnswerMapper examPaperAnswerMapper;
	
      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ExamPaperAnswer> list(Tablepar tablepar,String name){
	        ExamPaperAnswerExample testExample=new ExamPaperAnswerExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andCreateUserLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ExamPaperAnswer> list= examPaperAnswerMapper.selectByExample(testExample);
	        PageInfo<ExamPaperAnswer> pageInfo = new PageInfo<ExamPaperAnswer>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			ExamPaperAnswerExample example=new ExamPaperAnswerExample();
			example.createCriteria().andIdIn(lista);
			return examPaperAnswerMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ExamPaperAnswer selectByPrimaryKey(String id) {
				
			return examPaperAnswerMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ExamPaperAnswer record) {
		return examPaperAnswerMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ExamPaperAnswer record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return examPaperAnswerMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ExamPaperAnswer record, ExamPaperAnswerExample example) {
		
		return examPaperAnswerMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ExamPaperAnswer record, ExamPaperAnswerExample example) {
		
		return examPaperAnswerMapper.updateByExample(record, example);
	}

	@Override
	public List<ExamPaperAnswer> selectByExample(ExamPaperAnswerExample example) {
		
		return examPaperAnswerMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ExamPaperAnswerExample example) {
		
		return examPaperAnswerMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ExamPaperAnswerExample example) {
		
		return examPaperAnswerMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param examPaperAnswer
	 * @return
	 */
	public int checkNameUnique(ExamPaperAnswer examPaperAnswer){
		ExamPaperAnswerExample example=new ExamPaperAnswerExample();
		example.createCriteria().andCreateUserEqualTo(examPaperAnswer.getCreateUser());
		List<ExamPaperAnswer> list=examPaperAnswerMapper.selectByExample(example);
		return list.size();
	}


}
